<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <title>move3</title>
</head>

<body>
  <div id="app"></div>
  <!-- built files will be auto injected -->
  <script>
    (() => {
      // 声明：var let const fucntion
      function setRem() {
        console.log('setRem...');
        // 获取html的宽度（手机屏幕宽度）
        let htmlClientWidth = document.documentElement.clientWidth;
        // 手机屏幕宽度 / 设计稿屏幕宽度 * 你喜欢的单位
        const nowRem = htmlClientWidth / 375 * 10;
        if (htmlClientWidth > 640) {
          document.documentElement.style.fontSize = '10px';
        } else {
          // 设置 html的fontSize
          document.documentElement.style.fontSize = parseInt(nowRem) + 'px';
        }
      }
      setRem(); // 执行设置
      let timer;
      window.addEventListener('resize', () => {
        // 改变大小时直接先清除定时器
        clearTimeout(timer);
        timer = setTimeout(() => {
          console.log('窗口大小改变...');
          setRem();
        }, 100);
      });
    })();
  </script>
</body>

</html>